//
//  FirstViewController.m
//  集成ReactNative
//
//  Created by Admin on 2017/3/6.
//  Copyright © 2017年 Admin. All rights reserved.
//

#import "FirstViewController.h"
#import "titleView.h"
#import "PageContentView.h"
#import "SecondViewController.h"

@interface FirstViewController ()<titleViewDelegate,pageViewControllerDelegate>
@property (nonatomic,strong) titleView *titleV;
@property (nonatomic,strong) PageContentView *pageContentView;
@end
@implementation FirstViewController

#pragma mark - 懒加载
- (titleView *)titleV {
    if (_titleV == nil) {
        CGRect frame = CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, 40);
        NSArray *titleArray = @[@"推荐",@"学习",@"课程"];
        _titleV = [[titleView alloc]initWithFrame:frame titles:titleArray];
        _titleV.delegate = self;
        _titleV.backgroundColor = [UIColor whiteColor];
    }
    return _titleV;
}

#pragma mark - 懒加载
-(PageContentView *)pageContentView {
    if (_pageContentView == nil) {
        // 1.确定内容的frame
        CGFloat contentH = [UIScreen mainScreen].bounds.size.height - 20 - 44 - 40 - 44;
        CGRect contentFrame = CGRectMake(0, 64 + 40, [UIScreen mainScreen].bounds.size.width, contentH);
        NSMutableArray *childVcs = [NSMutableArray array];
        [childVcs addObject:[[SecondViewController alloc] init]];
        [childVcs addObject:[[SecondViewController alloc] init]];
        [childVcs addObject:[[SecondViewController alloc] init]];
        _pageContentView = [[PageContentView alloc]initWithFrame:contentFrame childVCs:childVcs parentViewController:self];
        _pageContentView.frame = contentFrame;
        // 2.确定所有的子控制器
        _pageContentView.delegate = self;
    }
    return _pageContentView;
}

- (void)titleViewSelectedIndex:(NSInteger)selectedIndex {
    NSLog(@"index...%ld",(long)selectedIndex);
    [self.pageContentView setCurrentIndex:selectedIndex];
}

- (void)pageContentView:(UIView *)contentView Progress:(CGFloat)progress sourceIndex:(NSInteger)sourceIndex targetIndex:(NSInteger)targetIndex {
    [self.titleV setTitleWithProgress:progress sourceIndex:sourceIndex targetIndex:targetIndex];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = false;
    [self.view addSubview:self.titleV];
    [self.view addSubview:self.pageContentView];
}

@end
